package demo2;

public enum EnumDemo {
    RED(1, "红色"), BLUE(2, "蓝色"), GREEN(3, "绿色");

    int val;
    String name;
    EnumDemo(int val, String name) {
        this.val = val;
        this.name = name;
    }

    public static void main(String[] args) {
        EnumDemo[] color = EnumDemo.values();
        for(int i = 0; i < color.length; i++) {
            System.out.println(color[i]);
            System.out.println(color[i].ordinal());
            System.out.println(color[i].val + " " + color[i].name);
        }
        System.out.println(RED.compareTo(GREEN));
        System.out.println(EnumDemo.valueOf("RED"));
    }

    public static void main1(String[] args) {
        EnumDemo color = RED;
        switch (color) {
            case RED:
                System.out.println("RED");
                break;
            case BLUE:
                System.out.println("BLUE");
                break;
            case GREEN:
                System.out.println("GREEN");
                break;
            default:
                System.out.println("No");
                break;
        }
    }
}
